package com.ys.service.base.impl;

import com.alibaba.fastjson.JSON;
import com.ys.entity.base.*;
import com.ys.entity.sys.YsCol;
import com.ys.mapper.base.TbUserPaySlipMapper;
import com.ys.mapper.base.TbUserPersonalTaxCountMapper;
import com.ys.service.base.TbUserPaySlipService;
import com.ys.service.base.TbUserPersonalTaxCountService;
import com.ys.util.CheckUtil;
import com.ys.vo.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import java.util.Map;


/**
 * 员工工资条信息表
 */
@Service("tbUserPaySlipService")
public class TbUserPaySlipServiceImpl implements TbUserPaySlipService {
	private static final Logger logger = LoggerFactory.getLogger(TbUserPaySlipServiceImpl.class);

	@Autowired
	private TbUserPaySlipMapper tbUserPaySlipMapper;

	@Autowired
	private TbUserPersonalTaxCountService tbUserPersonalTaxCountService;

	@Autowired
	private CheckUtil checkUtil;

	/**
	 * 通过员工月度绩效信息新增工资条信息
	 */
	@Override
	public 	String addByMonthPerformanceId(Long monthPerformanceId) throws Exception {
		String resMsg = "推送成功！";
		TbUserPaySlip tbUserPaySlip = new TbUserPaySlip();
		tbUserPaySlip.setStatus(1);

		Map<String,Object> tbUserMonthPerformance = getCountInfo(monthPerformanceId);
		if(tbUserMonthPerformance!=null){
			//绩效已申报，考勤已导入状态的才可以生成工资条
			if(tbUserMonthPerformance.get("attendanceStatus")==null || Integer.parseInt(tbUserMonthPerformance.get("attendanceStatus").toString())==0){
				return "考勤未导入，无法生成工资条";
			}
			int isReportItem = new TbUserMonthPerformanceReportItem()
					.setMonthPerformanceId(monthPerformanceId)
					.addLeftJoin("TB_UserMonthPerformanceReport P ON P.Bid = A.Pbid")
					.where("P.EffectStock = 1")
					.count();
			if(isReportItem<=0){
				return "绩效需要已申报状态的才可以生成工资条";
			}
			//排除已生成工资条的信息
			int hasAdd = new TbUserPaySlip().setMonthPerformanceId(monthPerformanceId).count();
			if(hasAdd>0){
				return "已生成工资条，无需重复推送";
			}
			tbUserPaySlip.setMonthPerformanceId(monthPerformanceId);//员工月度绩效信息表Id
			tbUserPaySlip.setRoleLevelId(Long.parseLong(tbUserMonthPerformance.get("roleLevelId").toString()));//岗位职级表Id（TB_JobLevel表Id）
			tbUserPaySlip.setUserId(tbUserMonthPerformance.get("userId").toString());//组织机构用户id
			tbUserPaySlip.setOrgId(tbUserMonthPerformance.get("orgId").toString());//组织机构id(TS_OrganizationInfo表OrgId)
			tbUserPaySlip.setSocialSecurityId(Long.parseLong(tbUserMonthPerformance.get("socialSecurityId").toString()));//社保管理表Id（TB_SocialSecurity表id）
			tbUserPaySlip.setMedicalInsuranceId(Long.parseLong(tbUserMonthPerformance.get("medicalInsuranceId").toString()));//医保管理表Id（TB_MedicalInsurance表id）
			tbUserPaySlip.setAccumulationFundId(Long.parseLong(tbUserMonthPerformance.get("accumulationFundId").toString()));//公积金管理表Id（TB_ProvidentFund表id）
			tbUserPaySlip.setAttendanceId(Long.parseLong(tbUserMonthPerformance.get("attendanceManageId").toString()));//考勤管理表Id（TB_Attendance表id）
			String pointMonth = tbUserMonthPerformance.get("pointMonth").toString();//评定年月（YYYY-MM）
			tbUserPaySlip.setPointMonth(pointMonth);
			tbUserPaySlip.setSlipStatus(0);//工资状态（0空、1个税已导入、2待发放、3已发放）
			tbUserPaySlip.setYearEndBonus(BigDecimal.ZERO);//年终奖，默认为0
			tbUserPaySlip.setOtherPerformance(BigDecimal.ZERO);//其他绩效，默认为0
			tbUserPaySlip.setOtherCost(BigDecimal.ZERO);//其他费用，默认为0
			tbUserPaySlip.setPersonalTax(BigDecimal.ZERO);//个人所得税
			//获取员工职级信息
			TbUserJobLevelManage tbUserJobLevelManage = new TbUserJobLevelManage().setId(Long.parseLong(tbUserMonthPerformance.get("userJobLevelManageId").toString())).queryFirst();
			if(tbUserJobLevelManage!=null){
				if(tbUserJobLevelManage.getAdditionalCost()!=null)tbUserPaySlip.setOtherPerformance(tbUserJobLevelManage.getAdditionalCost());
				if(tbUserJobLevelManage.getAdditionalCostExplain()!=null)tbUserPaySlip.setOtherPerformanceRemark(tbUserJobLevelManage.getAdditionalCostExplain());
			}

			//工资条计算
			tbUserPaySlip = countPaySlip(tbUserPaySlip,tbUserMonthPerformance);

			tbUserPaySlipMapper.insert(tbUserPaySlip);
		}
		return resMsg;
	}


	/**
	 * 删除
	 */
	@Override
	public R del(Long id) throws Exception {
		TbUserPaySlip tbUserPaySlip = new TbUserPaySlip().setId(id).queryFirst();
		//工资状态非空的不能删除
		if(tbUserPaySlip.getSlipStatus()!=0){
			return R.error("工资状态为“空”才可删除！");
		}
		tbUserPaySlipMapper.deleteTrue(id);
		return R.ok();
	}


	/**
	 * 个税导入
	 */
	@Override
	public R importUserTax(Long id) throws Exception {
		TbUserPaySlip tbUserPaySlip = new TbUserPaySlip().setId(id).queryFirst();
		if(tbUserPaySlip!=null && tbUserPaySlip.getSlipStatus()==0) {
			//新增个税统计表
			TbUserPersonalTaxCount tbUserPersonalTaxCount = tbUserPersonalTaxCountService.add(id);
			//本月应纳税额
			BigDecimal monthNeedPayTax = tbUserPersonalTaxCount.getMonthNeedPayTax();
			tbUserPaySlip.setSlipStatus(1);//导入后，工资状态变成个税已导入
			tbUserPaySlip.setPersonalTax(monthNeedPayTax);
			Map<String, Object> tbUserMonthPerformance = getCountInfo(tbUserPaySlip.getMonthPerformanceId());
			//工资条计算
			tbUserPaySlip = countPaySlip(tbUserPaySlip, tbUserMonthPerformance);
			tbUserPaySlipMapper.update(tbUserPaySlip);
		}else {
			return R.error();
		}
		return R.ok();
	}


	/**
	 * 个税导入手动修改刷新
	 */
	@Override
	public R importUserTaxByUpdate(Long id) throws Exception {
		TbUserPaySlip tbUserPaySlip = new TbUserPaySlip().setId(id).queryFirst();
		if(tbUserPaySlip!=null) {
			Map<String, Object> tbUserMonthPerformance = getCountInfo(tbUserPaySlip.getMonthPerformanceId());

			//工资条计算
			tbUserPaySlip = countPaySlip(tbUserPaySlip, tbUserMonthPerformance);
			tbUserPaySlipMapper.update(tbUserPaySlip);
			//新增个税统计表
			TbUserPersonalTaxCount tbUserPersonalTaxCount = tbUserPersonalTaxCountService.updateBySouDong(id);
			//本月应纳税额
			BigDecimal monthNeedPayTax = tbUserPersonalTaxCount.getMonthNeedPayTax();
			//tbUserPaySlip.setSlipStatus(1);//导入后，工资状态变成个税已导入
			tbUserPaySlip.setPersonalTax(monthNeedPayTax);

			//工资条计算
			tbUserPaySlip = countPaySlip(tbUserPaySlip, tbUserMonthPerformance);
			tbUserPaySlipMapper.update(tbUserPaySlip);
		}else {
			return R.error();
		}
		return R.ok();
	}

	/**
	 * 年终奖导入
	 */
	@Override
	public R importYearEndBonus(Long id) throws Exception {
		TbUserPaySlip tbUserPaySlipByOld = new TbUserPaySlip().setId(id).queryFirst();
		if(tbUserPaySlipByOld!=null && tbUserPaySlipByOld.getSlipStatus()==0){
			String pointMonth = tbUserPaySlipByOld.getPointMonth();
			String[] dateArr = pointMonth.split("-");
			String yearStr = dateArr[0];
			//年终奖限制一年一次
			int hasImportThisYear = new TbUserPaySlip()
					.where("A.YearEndBonus != 0")
					.where("A.PointMonth like '%"+yearStr+"%'")
					.setUserId(tbUserPaySlipByOld.getUserId())
					.count();
			if(hasImportThisYear<=0){
				TbUserJobLevelManage tbUserJobLevelManage = new TbUserJobLevelManage().setUserId(tbUserPaySlipByOld.getUserId()).queryFirst();
				if(tbUserJobLevelManage!=null){
					BigDecimal yearEndBonus = tbUserJobLevelManage.getYearEndBonus();
					tbUserPaySlipByOld.setYearEndBonus(yearEndBonus);
					Map<String,Object> tbUserMonthPerformance = getCountInfo(tbUserPaySlipByOld.getMonthPerformanceId());
					//工资条计算
					tbUserPaySlipByOld = countPaySlip(tbUserPaySlipByOld,tbUserMonthPerformance);
					tbUserPaySlipMapper.update(tbUserPaySlipByOld);
				}
			}
		}else {
			return R.error();
		}
		return R.ok();
	}



	/**
	 * 保存
	 */
	@Override
	public R save(Map<String, Object> params,Long menuId) throws Exception {
		logger.info("保存传参："+params);
		//参数验证
		String errorMsg = checkParams(params,menuId);
		if(errorMsg!=null && !"".equals(errorMsg)){
			return R.error(errorMsg);
		}
		TbUserPaySlip tbUserPaySlip = JSON.parseObject(JSON.toJSONString(params), TbUserPaySlip.class);
		TbUserPaySlip tbUserPaySlipByOld = new TbUserPaySlip().setId(tbUserPaySlip.getId()).queryFirst();
		if(tbUserPaySlipByOld!=null){
			if(tbUserPaySlip.getOtherPerformance()!=null)tbUserPaySlipByOld.setOtherPerformance(tbUserPaySlip.getOtherPerformance());
			if(tbUserPaySlip.getOtherPerformanceRemark()!=null)tbUserPaySlipByOld.setOtherPerformanceRemark(tbUserPaySlip.getOtherPerformanceRemark());
			if(tbUserPaySlip.getOtherCost()!=null)tbUserPaySlipByOld.setOtherCost(tbUserPaySlip.getOtherCost());
			if(tbUserPaySlip.getOtherCostRemark()!=null)tbUserPaySlipByOld.setOtherCostRemark(tbUserPaySlip.getOtherCostRemark());
			Map<String,Object> tbUserMonthPerformance = getCountInfo(tbUserPaySlipByOld.getMonthPerformanceId());
			//工资条计算
			tbUserPaySlipByOld = countPaySlip(tbUserPaySlipByOld,tbUserMonthPerformance);
			tbUserPaySlipMapper.update(tbUserPaySlipByOld);
		}
		return R.ok();
	}


	/**
	 * 参数验证
	 */
	public String checkParams(Map<String, Object> params, Long menuId) throws Exception {
		//获取pc字段数据
		List<YsCol> listField = new YsCol()
				.where("A.MenuId = "+menuId)
				.setOrderby("A.SortNo ASC")
				.queryList();
		//验证必填字段的非空；其他字段的长度限制、类型
		String backMsg = checkUtil.checkTableColLengthAndDataType("TB_UserPaySlip",listField,params,ysColItem->ysColItem.getFormEditRequired()!=null && ysColItem.getFormEditRequired() == 1);

		return backMsg;
	}


	//工资条计算
	@Override
	public TbUserPaySlip countPaySlip(TbUserPaySlip tbUserPaySlip,Map<String,Object> tbUserMonthPerformance){
		String pointMonth = tbUserMonthPerformance.get("pointMonth").toString();//评定年月（YYYY-MM）

		//*****计算： 绩效薪资 = 绩效薪资/月  *人事绩效评分/100
		BigDecimal perbasedSalary = new BigDecimal(tbUserMonthPerformance.get("perbasedSalary").toString());//绩效薪资/月
		BigDecimal hrPerformancePoint = new BigDecimal(tbUserMonthPerformance.get("hrPerformancePoint").toString());//人事绩效评分
		BigDecimal performanceSalary = perbasedSalary
				.multiply(hrPerformancePoint)
				.divide(new BigDecimal(100),2,BigDecimal.ROUND_HALF_UP);//保留2位小数，四舍五入
		tbUserPaySlip.setPerformanceSalary(performanceSalary);

		//*****计算： 季度提奖 = 季度提奖/月*3 (每年3月、6月、9月、12月产生，其余月份为0)
		String[] dateArr = pointMonth.split("-");
		String monthStr = dateArr[1];
		if(monthStr.equals("03") || monthStr.equals("06") || monthStr.equals("09") || monthStr.equals("12") ){
			BigDecimal quarterlyBonus = new BigDecimal(tbUserMonthPerformance.get("quarterlyBonus").toString());//季度提奖/月
			BigDecimal quarterBonus = (quarterlyBonus.multiply(new BigDecimal(3))).setScale(2, BigDecimal.ROUND_HALF_UP);
			tbUserPaySlip.setQuarterBonus(quarterBonus);
		}else {
			tbUserPaySlip.setQuarterBonus(BigDecimal.ZERO);
		}

		//*****计算：考勤绩效
		//旷工（小时）*3*发薪标准/(月考勤标准（天）*日考勤标准（小时）)
		BigDecimal noWorkHour = new BigDecimal(tbUserMonthPerformance.get("noWorkHour").toString());//旷工（小时）
		BigDecimal salaryStandard = new BigDecimal(tbUserMonthPerformance.get("salaryStandard").toString());//发薪标准/月
		BigDecimal monthlyAsDay = new BigDecimal(tbUserMonthPerformance.get("monthlyAsDay").toString());//(月考勤标准（天）
		BigDecimal dailyAsHour = new BigDecimal(tbUserMonthPerformance.get("dailyAsHour").toString());//考勤标准（小时）
		BigDecimal noWorkHourCount = BigDecimal.ZERO;
		if(monthlyAsDay.compareTo(BigDecimal.ZERO)!=0 && dailyAsHour.compareTo(BigDecimal.ZERO)!=0){
			noWorkHourCount = noWorkHour
					.multiply(new BigDecimal(3))
					.multiply(salaryStandard)
					.divide(monthlyAsDay.multiply(dailyAsHour),2,BigDecimal.ROUND_HALF_UP);
		}
		//迟到（次）*20
		BigDecimal lateTimes = new BigDecimal(tbUserMonthPerformance.get("lateTimes").toString());//迟到（次）
		BigDecimal lateTimesCount = (lateTimes.multiply(new BigDecimal(20))).setScale(2, BigDecimal.ROUND_HALF_UP);
		//漏打卡（次）*20
		BigDecimal noSignIn = new BigDecimal(tbUserMonthPerformance.get("noSignIn").toString());//迟到（次）
		BigDecimal noSignInCount = (noSignIn.multiply(new BigDecimal(20))).setScale(2, BigDecimal.ROUND_HALF_UP);
		//旧：病假（小时）/2*发薪标准/(月考勤标准（天）*日考勤标准（小时）)
		//新：病假（小时）*0.4*发薪标准/(月考勤标准（天）*日考勤标准（小时）)
		BigDecimal illHolidayHour = new BigDecimal(tbUserMonthPerformance.get("illHolidayHour").toString());//病假（小时）
		BigDecimal illHolidayHourCount = BigDecimal.ZERO;
		if(monthlyAsDay.compareTo(BigDecimal.ZERO)!=0 && dailyAsHour.compareTo(BigDecimal.ZERO)!=0){
			illHolidayHourCount = illHolidayHour
					//.divide(new BigDecimal(2),2,BigDecimal.ROUND_HALF_UP)
					.multiply(new BigDecimal(0.4))
					.multiply(salaryStandard)
					.divide(monthlyAsDay.multiply(dailyAsHour),2,BigDecimal.ROUND_HALF_UP);
		}
		//（事假-其他（小时）-带薪事假-其他（小时））*发薪标准/(月考勤标准（天）*日考勤标准（小时）)，与0需大值
		BigDecimal thingHolidayHourByOther = new BigDecimal(tbUserMonthPerformance.get("thingHolidayHourByOther").toString());//事假-其他（小时）
		BigDecimal paidPersonalLeave = new BigDecimal(tbUserMonthPerformance.get("paidPersonalLeave").toString());//带薪事假-其他（小时）
		BigDecimal thingHolidayHourByOtherCount = BigDecimal.ZERO;
		if(monthlyAsDay.compareTo(BigDecimal.ZERO)!=0 && dailyAsHour.compareTo(BigDecimal.ZERO)!=0){
			thingHolidayHourByOtherCount = (thingHolidayHourByOther.subtract(paidPersonalLeave))
					.multiply(salaryStandard)
					.divide(monthlyAsDay.multiply(dailyAsHour),2,BigDecimal.ROUND_HALF_UP);
		}

		if(thingHolidayHourByOtherCount.compareTo(BigDecimal.ZERO)<0){//小于0时，强改成0
			thingHolidayHourByOtherCount = BigDecimal.ZERO;
		}
		//考勤绩效
		BigDecimal attendancePerformance = (noWorkHourCount//旷工罚款
				.add(lateTimesCount)//迟到罚款
				.add(noSignInCount)//漏打卡罚款
				.add(illHolidayHourCount)//病假罚款
				.add(thingHolidayHourByOtherCount))//事假罚款
				.setScale(2, BigDecimal.ROUND_HALF_UP);
		tbUserPaySlip.setAttendancePerformance(attendancePerformance);

		//*****计算：应发工资 = 基本底薪+岗位薪资+绩效薪资+交通补贴+餐饮补贴+岗位提奖+季度提奖+年终奖-考勤绩效+其他绩效
		BigDecimal basicSalary = new BigDecimal(tbUserMonthPerformance.get("basicSalary").toString());//基本底薪
		BigDecimal positionSalary = new BigDecimal(tbUserMonthPerformance.get("positionSalary").toString());//岗位薪资/月
		//BigDecimal perbasedSalary = new BigDecimal(tbUserMonthPerformance.get("perbasedSalary").toString());//绩效薪资
		BigDecimal transSubsidy = new BigDecimal(tbUserMonthPerformance.get("transSubsidy").toString());//交通补贴/月
		BigDecimal cateringSubsidy = new BigDecimal(tbUserMonthPerformance.get("cateringSubsidy").toString());//餐饮补贴/月
		BigDecimal jobBonus = new BigDecimal(tbUserMonthPerformance.get("jobBonus").toString());//岗位提奖/月
		BigDecimal quarterBonus = tbUserPaySlip.getQuarterBonus();//季度提奖
		BigDecimal yearEndBonus = tbUserPaySlip.getYearEndBonus();//年终奖
		//考勤绩效：attendancePerformance
		BigDecimal otherPerformance = tbUserPaySlip.getOtherPerformance();//其他绩效
		BigDecimal wagesPay = (basicSalary//+基本底薪
				.add(positionSalary)//+岗位薪资/月
				.add(performanceSalary)//+绩效薪资
				.add(transSubsidy)//+交通补贴/月
				.add(cateringSubsidy)//+餐饮补贴/月
				.add(jobBonus)//+岗位提奖/月
				.add(quarterBonus)//+季度提奖
				.add(yearEndBonus)//+年终奖
				.subtract(attendancePerformance)//-考勤绩效
				.add(otherPerformance))//+其他绩效
				.setScale(2, BigDecimal.ROUND_HALF_UP);
		tbUserPaySlip.setWagesPay(wagesPay);//应发工资

		//*****计算：养老保险（单位） = 社保基数*养老保险比例（单位）
		BigDecimal retirementCompany = new BigDecimal(tbUserMonthPerformance.get("piUnitMonth").toString());
		tbUserPaySlip.setRetirementCompany(retirementCompany);

		//*****计算：养老保险（个人） = 社保基数*养老保险比例（个人）
		BigDecimal retirementPersonal = new BigDecimal(tbUserMonthPerformance.get("piIndividualMonth").toString());
		tbUserPaySlip.setRetirementPersonal(retirementPersonal);

		//*****计算：失业保险（单位） = 社保基数*失业保险比例（单位）
		BigDecimal loseWorkCompany = new BigDecimal(tbUserMonthPerformance.get("uiUnitMonth").toString());
		tbUserPaySlip.setLoseWorkCompany(loseWorkCompany);

		//*****计算：失业保险（个人） = 社保基数*失业保险比例（个人）
		BigDecimal loseWorkPersonal = new BigDecimal(tbUserMonthPerformance.get("uiIndividualMonth").toString());
		tbUserPaySlip.setLoseWorkPersonal(loseWorkPersonal);

		//*****计算：工伤保险（单位） = 社保基数*工伤保险比例（单位）
		BigDecimal injuryCompany = new BigDecimal(tbUserMonthPerformance.get("wiiUnitMonth").toString());
		tbUserPaySlip.setInjuryCompany(injuryCompany);

		//*****计算：医疗保险（单位） = 医保基数*医疗保险比例（单位）
		BigDecimal healthCompany = new BigDecimal(tbUserMonthPerformance.get("miUnitMoonth").toString());
		tbUserPaySlip.setHealthCompany(healthCompany);

		//*****计算：医疗保险（个人） = 医保基数*医疗保险比例（个人）
		BigDecimal healthPersonal = new BigDecimal(tbUserMonthPerformance.get("miIndividualMonth").toString());
		tbUserPaySlip.setHealthPersonal(healthPersonal);

		//*****计算：生育保险（单位） = 医保基数*生育保险比例（单位）
		BigDecimal birthCompany = new BigDecimal(tbUserMonthPerformance.get("miUnitMonth").toString());
		tbUserPaySlip.setBirthCompany(birthCompany);

		//*****计算：公积金（单位） = 公积金基数*公积金比例（单位）
		BigDecimal accumulationFundCompany = new BigDecimal(tbUserMonthPerformance.get("pfUnitMonth").toString());
		tbUserPaySlip.setAccumulationFundCompany(accumulationFundCompany);

		//*****计算：公积金（个人） = 公积金基数*公积金比例（个人）
		BigDecimal accumulationFundPersonal = new BigDecimal(tbUserMonthPerformance.get("pfIndividualMonth").toString());
		tbUserPaySlip.setAccumulationFundPersonal(accumulationFundPersonal);

		//*****计算：应付工资 = 应发工资-养老保险（个人）-失业保险（个人）-医疗保险（个人）-公积金（个人）+其他费用
		//应发工资 wagesPay ；养老保险（个人） retirementPersonal；
		//失业保险（个人）loseWorkPersonal；医疗保险（个人）healthPersonal；公积金（个人）accumulationFundPersonal
		BigDecimal otherCost = tbUserPaySlip.getOtherCost();//其他费用
		BigDecimal needPaySlip = (wagesPay//应发工资
				.subtract(retirementPersonal)//养老保险（个人）
				.subtract(loseWorkPersonal)//失业保险（个人）
				.subtract(healthPersonal)//医疗保险（个人）
				.subtract(accumulationFundPersonal)//公积金（个人）
				.add(otherCost))//其他费用
				.setScale(2, BigDecimal.ROUND_HALF_UP);
		tbUserPaySlip.setNeedPaySlip(needPaySlip);

		//个税收入=应发工资+其他费用
		BigDecimal taxPaySlip = wagesPay.add(otherCost);
		tbUserPaySlip.setTaxPaySlip(taxPaySlip);

		//*****计算：实发工资 = 应付工资-个人所得税
		BigDecimal personalTax = tbUserPaySlip.getPersonalTax();//个人所得税
		BigDecimal realityPaySlip = (tbUserPaySlip.getNeedPaySlip().subtract(personalTax)).setScale(2, BigDecimal.ROUND_HALF_UP);
		tbUserPaySlip.setRealityPaySlip(realityPaySlip);

		return tbUserPaySlip;
	}

	//获取工资表计算信息
	@Override
	public Map<String,Object> getCountInfo(Long monthPerformanceId){
		Map<String,Object> tbUserMonthPerformance = new TbUserMonthPerformance()

				.addField("A.RoleLevelId AS roleLevelId")//岗位职级表Id（TB_JobLevel表id）
				.addField("A.UserId AS userId")//组织机构用户id
				.addField("A.OrgId AS orgId")//组织机构id(TS_OrganizationInfo表OrgId)
				.addField("A.SocialSecurityId AS socialSecurityId")//社保管理表Id（TB_SocialSecurity表id）
				.addField("A.medicalInsuranceId AS medicalInsuranceId")//医保管理表Id（TB_MedicalInsurance表id）
				.addField("A.AccumulationFundId AS accumulationFundId")//公积金管理表Id（TB_ProvidentFund表id）
				.addField("A.AttendanceId AS attendanceManageId")//考勤管理表Id（TB_Attendance表id）

				.addField("A.PerbasedSalary AS perbasedSalary")//绩效薪资/月
				.addField("A.QuarterlyBonus AS quarterlyBonus")//季度提奖/月
				.addField("A.SalaryStandard AS salaryStandard")//发薪标准/月
				.addField("A.BasicSalary AS basicSalary")//基本底薪/月
				.addField("A.PositionSalary AS positionSalary")//岗位薪资/月
				.addField("A.TransSubsidy AS transSubsidy")//交通补贴/月
				.addField("A.CateringSubsidy AS cateringSubsidy")//餐饮补贴/月
				.addField("A.FixsalaryStandard AS fixsalaryStandard")//定薪标准

				.addField("A.MonthlyAsDay AS monthlyAsDay")//月考勤标准（天）
				.addField("A.DailyAsHour AS dailyAsHour")//日考勤标准（小时）/月
				.addField("A.PaidPersonalLeave AS paidPersonalLeave")//带薪事假-其他（小时）

				.addField("A.PiUnitMonth AS piUnitMonth")//养老保险（单位）
				.addField("A.PiIndividualMonth AS piIndividualMonth")//养老保险（个人）
				.addField("A.UiUnitMonth AS uiUnitMonth")//失业保险（单位）
				.addField("A.UiIndividualMonth AS uiIndividualMonth")//失业保险（个人）
				.addField("A.WiiUnitMonth AS wiiUnitMonth")//工伤保险（单位）

				.addField("A.MiUnitMoonth AS miUnitMoonth")//医疗保险（单位）
				.addField("A.MiIndividualMonth AS miIndividualMonth")//医疗保险（个人）
				.addField("A.MiUnitMonth AS miUnitMonth")//生育保险（单位）

				.addField("A.PfUnitMonth AS pfUnitMonth")//公积金（单位）
				.addField("A.PfIndividualMonth AS pfIndividualMonth")//公积金（个人）


				/*
				.addField("JL.PerbasedSalary AS perbasedSalary")//绩效薪资/月
				.addField("JL.QuarterlyBonus AS quarterlyBonus")//季度提奖/月
				.addField("JL.SalaryStandard AS salaryStandard")//发薪标准/月
				.addField("JL.BasicSalary AS basicSalary")//基本底薪/月
				.addField("JL.PositionSalary AS positionSalary")//岗位薪资/月
				.addField("JL.TransSubsidy AS transSubsidy")//交通补贴/月
				.addField("JL.CateringSubsidy AS cateringSubsidy")//餐饮补贴/月
				.addField("JL.FixsalaryStandard AS fixsalaryStandard")//定薪标准


				.addField("AD.MonthlyAsDay AS monthlyAsDay")//月考勤标准（天）
				.addField("AD.DailyAsHour AS dailyAsHour")//日考勤标准（小时）/月
				.addField("AD.PaidPersonalLeave AS paidPersonalLeave")//带薪事假-其他（小时）

				//.addField("SS.PiRatioUnit AS piRatioUnit")//养老保险比例（单位）
				//.addField("SS.PiRatioIndividual AS piRatioIndividual")//养老保险比例（个人）
				//.addField("SS.UiRatioUnit AS uiRatioUnit")//失业保险比例（单位）
				//.addField("SS.UiRatioIndividual AS uiRatioIndividual")//失业保险比例（个人）
				//.addField("SS.WiiRatioUnit AS wiiRatioUnit")//工伤保险比例（单位）
				.addField("SS.PiUnitMonth AS piUnitMonth")//养老保险（单位）
				.addField("SS.PiIndividualMonth AS piIndividualMonth")//养老保险（个人）
				.addField("SS.UiUnitMonth AS uiUnitMonth")//失业保险（单位）
				.addField("SS.UiIndividualMonth AS uiIndividualMonth")//失业保险（个人）
				.addField("SS.WiiUnitMonth AS wiiUnitMonth")//工伤保险（单位）


				//.addField("MI.MiBase AS miBase")//医保基数
				//.addField("MI.MiRatioUnit AS miRatioUnit")//医疗保险比例（单位）
				//.addField("MI.MiRatioIndividual AS miRatioIndividual")//医疗保险比例（个人）
				//.addField("MI.MaternityinsuranceRatioUnit AS maternityinsuranceRatioUnit")//生育保险比例（单位）
				.addField("MI.MiUnitMoonth AS miUnitMoonth")//医疗保险（单位）
				.addField("MI.MiIndividualMonth AS miIndividualMonth")//医疗保险（个人）
				.addField("MI.MiUnitMonth AS miUnitMonth")//生育保险（单位）


				//.addField("PF.HousingPfBase AS housingPfBase")//公积金基数
				//.addField("PF.PfRatioUnit AS pfRatioUnit")//公积金比例（单位）
				//.addField("PF.PfRatioIndividual AS pfRatioIndividual")//公积金比例（个人）
				.addField("PF.PfUnitMonth AS pfUnitMonth")//公积金（单位）
				.addField("PF.PfIndividualMonth AS pfIndividualMonth")//公积金（个人）


				//.addLeftJoin("TB_UserJobLevelManage JM ON JM.Id = A.UserJobLevelManageId")//员工职级管理
				.addLeftJoin("TB_JobLevel JL ON JL.Id = A.RoleLevelId")//岗位职级表
				.addLeftJoin("TB_Attendance AD ON AD.Id = A.AttendanceId")//考勤管理表
				.addLeftJoin("TB_SocialSecurity SS ON SS.Id = A.SocialSecurityId")//社保管理表
				.addLeftJoin("TB_MedicalInsurance MI ON MI.Id = A.MedicalInsuranceId")//医保管理
				.addLeftJoin("TB_ProvidentFund PF ON PF.Id = A.AccumulationFundId")//公积金管理表

				 */

				.setId(monthPerformanceId)
				.queryFirstMap();
		return tbUserMonthPerformance;
	}


}
